package 题目集.贡献法;

import java.util.Arrays;
import java.util.Scanner;

public class 孤独的牛 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        char[] chars = sc.nextLine().toCharArray();
        int[] l = new int[chars.length];
        int[] r = new int[chars.length];
        int[] pre = new int[128];
        Arrays.fill(pre, -1);
        for (int i = 0; i < chars.length; i++) {
            l[i] = pre[chars[i]];
            pre[chars[i]] = i;
        }
        Arrays.fill(pre, r.length);
        for (int i = chars.length - 1; i >= 0; i--) {
            r[i] = pre[chars[i]];
            pre[chars[i]] = i;
        }
        long res = 0;
        for (int i = 0; i < l.length; i++) {
            int ln = i - l[i] - 1;
            int rn = r[i] - i - 1;
            if (ln > 0 && rn > 0) {
                res += ((long) ln * rn) + (ln - 1) + (rn - 1); //除了最靠近的数，其他数都能取到另一侧的所有数，最靠近的数只能取到（ln-1）
            } else if (ln > 0) {
                res += ln - 1;
            } else if (rn > 0) {
                res += rn - 1;
            }
        }
        System.out.println(res);
    }
}
